// pages/register/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: '', // 手机号
    code: '', // 验证码
    password: '', // 密码
    isPassword: '', // 确认密码
    shopName:"",
    shopLocation:"",
    userName:""
    
  },

  // 验证手机号
  verifyPhoneTap: function (e) {
    // console.log(e, 'e');
    var phone = e.detail.value;
    this.setData({
      phone: phone
    })
  },
  // 验证码
  verifyCodeTap: function (e) {
    var code = e.detail.value;
    this.setData({
      code: code
    })
  },
  // 验证密码
  verifyPasswordBlur: function (e) {
    var password = e.detail.value;
    this.setData({
      password: password
    })
  },
  // 确认密码
  isPasswordBlur: function (e) {
    var isPassword = e.detail.value;
    this.setData({
      isPassword: isPassword
    })
  },
   // 用户昵称
   verifyNameTap: function (e) {
    var userName = e.detail.value;
    this.setData({
      userName: userName
    })
  },
   // 店铺名称
   verifyShopTap: function (e) {
    var shopName = e.detail.value;
    this.setData({
      shopName: shopName
    })
  },
   // 店铺地址
   verifyLocationTap: function (e) {
    var shopLocation = e.detail.value;
    this.setData({
      shopLocation: shopLocation
    })
  },
  // 注册
  registerTap: function (e) {
    if (!(/^1[3|4|5|7|8]\d{9}$/.test(this.data.phone))) {
      wx.showToast({
        title: '手机号码有误，请重填',
        icon: 'none',
        duration: 2000
      })
      return false;
    };
    if (this.data.password == undefined || this.data.password.length < 6) {
      wx.showToast({
        title: '请输入至少6位数密码',
        icon: 'none',
        duration: 2000
      })
      return false;
    };
    if (this.data.isPassword != this.data.password) {
      wx.showToast({
        title: '两次输入的密码不一致',
        icon: 'none',
        duration: 2000
      })
      return false;
    };
    if (this.data.shopName == '') {
      wx.showToast({
        title: '请输入店铺名称',
        icon: 'none',
        duration: 2000
      })
      return false;
    };
    if (this.data.userName == '') {
      wx.showToast({
        title: '请输入用户名',
        icon: 'none',
        duration: 2000
      })
      return false;
    };
    if (this.data.shopLocation == '') {
      wx.showToast({
        title: '请输入店铺地址',
        icon: 'none',
        duration: 2000
      })
      return false;
    };
    var data = {
      mobile:this.data.phone,
      password:this.data.password,
      username:this.data.userName,
      shopname:this.data.shopName,
      address:this.data.shopLocation

    }
    wx.request({
      url: 'https://www.didi93.xyz//index.php/index/user/registerwxapp.html',
      header: {
        'content-type': 'application/x-www-form-urlencoded',
      },
      method: 'POST',
      data: data,
      success: function (res) {
        if(res.data.code == 1){
          wx.showModal({
            title: '提示',
            content: res.data.msg,
            success (res) {
              if (res.confirm) {
                wx.switchTab({
                  url: '/index'
                })
              } else if (res.cancel) {
              }
            }
          })
        }else{
          wx.showModal({
            title: '提示',
            content: res.data.msg,
            success (res) {
              if (res.confirm) {
              } else if (res.cancel) {
              }
            }
          })
        }
      },
      fail: function (res) {
       
      },
    });
  },
  // 返回登录页面
  returnLoginTap: function (e) {
    wx.navigateTo({
      url: '/pages/login/index',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
